Generate a documentation full of graphs, making the script #file:index.ts more intuitive and easy to understand
Here is a documentation draft for your index.ts script, featuring intuitive diagrams and explanations to make the plugin’s logic and flow easy to understand.
This plugin automatically expands or folds blocks in Siyuan based on their content when a page is loaded. It listens to specific events, checks block attributes, and manages their expanded/collapsed state for a smoother user experience.
flowchart TD
A[Plugin Load] --> B[Register Event Listeners]
B --> C{Event Occurs}
C -->|loaded-protyle-static| D[Check Block Attributes]
D -->|Folded| E[Expand Block & Register]
D -->|Not Folded| F[Do Nothing]
C -->|destroy-protyle| G[Fold Back Registered Blocks]
G --> H[Clear Registered List]
sequenceDiagram
participant User
participant Plugin
User->>Plugin: Load Plugin
Plugin->>Plugin: onload()
Plugin->>Plugin: registerEventListeners()
User->>Plugin: Disable/Unload Plugin
Plugin->>Plugin: onunload()
Plugin->>Plugin: unregisterEventListeners()
User->>Plugin: Uninstall Plugin
Plugin->>Plugin: uninstall()
flowchart TD
A[Event: loaded-protyle-static] --> B[Get Block ID]
B --> C[Fetch Block Attributes]
C --> D{Is Folded?}
D -- Yes --> E[Expand Block]
E --> F[Register Block for Refolding]
D -- No --> G[Do Nothing]
flowchart TD
A[Event: destroy-protyle] --> B[Iterate Registered Blocks]
B --> C[Fold Each Block]
C --> D[Clear Registered List]
loaded-protyle-static
(expand/fold logic)destroy-protyle
(refold logic)latestFoldedBlockIdArray
.latestFoldedBlockIdArray
when the protyle instance is destroyed.myDebug = true
to enable detailed logging.window.myPathVar
to specify which part of the event object to log.classDiagram
class PluginSample {
-fnLogArgsExecCount: number
-latestFoldedBlockIdArray: string[]
-isMobile: boolean
+onload()
+onunload()
+uninstall()
+registerEventListeners()
+unregisterEventListeners()
+tryExpandBlock()
+tryFoldBlock()
+tryFoldBlockWhenDestroyProtype()
+logArgsCallback()
}
PluginSample --|> Plugin
Let me know if you want this as a Markdown file in your project, or need more diagrams or details!